<template>
	<view class="all">
		<image class="head" src="../../../static/img/indexBanner.png" mode=""></image>
		<view class="body">
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">姓名</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入姓名" />
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">入驻区域</text>
				</view>
				<view class="right">
					<input type="text" placeholder="区域" />
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">性别</text>
				</view>
				<view class="right">
					男 女
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">手机号</text>
				</view>
				<view class="right">
					<input type="number" placeholder="请输入手机号" maxlength="11" />
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">现住地址</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入现住地址" />
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">工作经验</text>
				</view>
				<view class="right">
					有 无
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s1">*</text>
					<text class="s2">服务项目</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入服务项目" />
				</view>
			</view>
			<view class="box flex">
				<view class="left">
					<text class="s2">推荐人</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入推荐人码" />
				</view>
			</view>
			<view class="box">
				<view class="left">
					<text class="s2">自我介绍</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入自我介绍" />
				</view>
			</view>
		</view>
		<view class="body">
			<view class="box">
				<view class="left" style="margin-bottom: 15px;">
					<text class="s1">*</text>
					<text class="s2">工作照</text>
				</view>
				<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
			</view>
		</view>
		<view class="body">
			<view class="box">
				<view class="left" style="margin-bottom: 15px;">
					<text class="s1">*</text>
					<text class="s2">生活照</text>
				</view>
				<u-upload :fileList="fileList2" @afterRead="afterRead1" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
			</view>
		</view>
		<view class="body">
			<view class="box">
				<view class="left" style="margin-bottom: 15px;">
					<text class="s1">*</text>
					<text class="s2">身份证</text>
				</view>
				<u-upload :fileList="fileList3" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
			</view>
		</view>
		<view class="body">
			<view class="box">
				<view class="left" style="margin-bottom: 15px;">
					<text class="s1">*</text>
					<text class="s2">资格证</text>
				</view>
				<u-upload :fileList="fileList4" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
			</view>
		</view>
		<view class="body">
			<view class="box">
				<view class="left" style="margin-bottom: 15px;">
					<text class="s1">*</text>
					<text class="s2">健康证</text>
				</view>
				<u-upload :fileList="fileList5" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
			</view>
		</view>
		<view class="body">
			<view class="box">
				<view class="left" style="margin-bottom: 15px;">
					<text class="s1">*</text>
					<text class="s2">营业执照</text>
				</view>
				<u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1: [],
				fileList2: [],
				fileList3: [],
				fileList4: [],
				fileList5: [],
				fileList6: [],
			};
		},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			async afterRead1(event) {
				console.log(event.name);
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'https://admin.lykangshu.top/api/common/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							const ret = JSON.parse(res.data)
							console.log(ret);
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.all {
		background-color: #f5f5f5;
		min-height: calc(100vh - 44px);
		display: flex;
		flex-direction: column;

		.head {
			width: 100%;
			height: 200px;
		}

		.body {
			width: 90%;
			margin: 10px auto;
			// padding: 10px;
			background-color: #ffffff;
			box-sizing: border-box;
			border-radius: 10px;

			.box {
				// margin: 10px 0;
				padding: 10px;
				border-bottom: 1px solid #eeeeee;

				.left {
					width: 30%;

					.s1 {
						color: #FB774B;
						font-size: 12px;
					}

					.s2 {
						font-size: 15px;
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						color: #333333;
					}
				}

				.right {
					flex: 1;
					font-size: 15px;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #999999;

					input {
						font-size: 15px;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
				}

			}
		}
	}
</style>